package com.wz.dhs.controller.common;

import com.wz.dhs.model.common.Result;
import com.wz.dhs.utils.OssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RequestMapping("/file")
@Slf4j
@Validated
@RestController
@Api(tags = "文件相关")
public class FileController {


    @Autowired
    private OssUtil ossUtil;

    /**
     * 上传文件接口
     *
     * @param file 待上传的文件
     * @return 文件的访问URL
     */
    @PostMapping("/upload")
    @ApiOperation(value = "上传文件")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return Result.fail("文件为空，请选择文件后重试！");
        }
        // 调用OSS工具类上传文件
        return Result.data(ossUtil.uploadFile(file));
    }
}






